<?php

namespace plugin\admin\app\controller;

use plugin\admin\app\model\VideoModel;
use support\Request;
use support\Response;
use plugin\admin\app\model\VideoChapter;
use plugin\admin\app\controller\Crud;
use support\exception\BusinessException;

/**
 * 视频剧集 
 */
class VideoChapterController extends Crud
{
    
    /**
     * @var VideoChapter
     */
    protected $model = null;

    /**
     * 构造函数
     * @return void
     */
    public function __construct()
    {
        $this->model = new VideoChapter;
    }
    
    /**
     * 浏览
     * @return Response
     */
    public function index(): Response
    {
        return view('video-chapter/index');
    }

    /**
     * 查询
     * @param Request $request
     * @return Response
     * @throws BusinessException
     */
    public function select(Request $request): Response
    {
        $request->inputSet('isdel',0);
        $request->inputSet('field','created_at');
        $request->inputSet('order','desc');
        return parent::select($request);
    }

    /**
     * 插入
     * @param Request $request
     * @return Response
     * @throws BusinessException
     */
    public function insert(Request $request): Response
    {
        if ($request->method() === 'POST') {
            //获取视频标题
            $title = (new VideoModel())->where(['video_sn'=>$request->post('video_sn')])->value('title');
            $request->inputSet('title',$title);
            return parent::insert($request);
        }
        return view('video-chapter/insert');
    }


    /**
     * 更新
     * @param Request $request
     * @return Response
     * @throws BusinessException
    */
    public function update(Request $request): Response
    {
        if ($request->method() === 'POST') {
            //获取视频标题
            $title = (new VideoModel())->where(['video_sn'=>$request->post('video_sn')])->value('title');
            $request->inputSet('title',$title);
            return parent::update($request);
        }
        return view('video-chapter/update');
    }

    /**
     * 删除
     * @param Request $request
     * @return Response
     * @throws BusinessException
     */
    public function delete(Request $request): Response
    {
        $ids = $this->deleteInput($request);
        $this->doIsDelete($ids);
        return $this->json(0);
    }

}
